<%--
  Created by IntelliJ IDEA.
  User: 王韫琛
  Date: 2021/2/2
  Time: 2:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>迁出申请处理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/webjars/layui/2.5.6/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/webjars/layui/2.5.6/layui.all.js">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/webjars/layui/2.5.6/layui.js">
</head>
<body>
<%--修改用户信息界面--%>
<div id="form_body" style="text-align: center;display: none" >
    <br>
    <br>
    <div class="layui-inline">
        <form id="dataFrm" class="layui-form  layui-form-pane" lay-filter="dataFrm">
            <div class="layui-form-item">
                <label class="layui-form-label" for="username" style="width: 160px">用户名:</label>
                <div class="layui-input-inline">
                    <input type="text" name="username" id="username" class="layui-input" required lay-verify="required"
                           disabled lay-reqText="请输入用户名" placeholder="请输入用户名" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="name" style="width: 160px">姓名:</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" readonly="true" id="name" class="layui-input" required lay-verify="required"
                           lay-reqText="请输入姓名" placeholder="请输入姓名" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="gender"style="width: 160px">性别:</label>
                <div class="layui-input-inline">
                    <input  disabled type="radio" name="gender" id="gender" value="男" title="男" checked="checked">
                    <input   disabled type="radio" name="gender" value="女" title="女">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="age" style="width: 160px">年龄:</label>
                <div class="layui-input-inline">
                    <input type="text"  readonly="true" name="age" id="age" class="layui-input" required lay-verify="required"
                           lay-reqText="请输入年龄" placeholder="请输入年龄" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="phone" style="width: 160px">手机号:</label>
                <div class="layui-input-inline">
                    <input type="text"  readonly="true" name="phone" id="phone" class="layui-input" required lay-verify="required|phone"
                           lay-reqText="请输入正确的手机号" placeholder="请输入手机号" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="identity_card" style="width: 160px">身份证号:</label>
                <div class="layui-input-inline">
                    <input type="text"  readonly="true" name="identity_card" id="identity_card" class="layui-input" required lay-verify="identity"
                           lay-reqText="身份证号" placeholder="身份证号" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="proof"  style="width: 160px">七日内核算证明:</label>
                <div class="layui-input-inline">
                    <input  disabled type="radio" name="proof" id="proof" value="有" title="有" checked="checked">
                    <input  disabled type="radio" name="proof" value="无" title="无">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="destination" style="width: 160px">目的地:</label>
                <div class="layui-input-inline">
                    <input  readonly="true" type="text" name="destination" id="destination" class="layui-input" required lay-verify="required"
                           lay-reqText="请输入目的地" placeholder="请输入目的地" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="adopt" style="width: 160px">是否通过:</label>
                <div class="layui-input-inline">
                    <input type="radio" name="adopt" id="adopt" value="是" title="是" checked="checked">
                    <input type="radio" name="adopt" value="否" title="否">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="test1" style="width: 160px">审批通过时间:</label>
                <div class="layui-input-inline">
                    <input  type="text" name="addtime" required lay-verify="required|data" class="layui-input" id="test1">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label" for="remark">备注:</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" id="remark" name="remark" class="layui-textarea"></textarea>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-inline" style="padding-left: 45px">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <button class="layui-btn" lay-submit lay-filter="doSubmit" lay-event="add">提交</button>
                </div>
            </div>

        </form>
    </div>
</div>
<%--用户信息显示--%>
<br/>
<%--搜索表单开始--%>
<form class="layui-form layui-form-pane" method="post">
    &nbsp;&nbsp;输入身份证搜索：
    <div class="layui-inline">
        <input class="layui-input" name="identity_card" lay-verify="required|identity">
    </div>
    <button class="layui-btn" lay-submit lay-filter="doSearch">搜索</button>
</form>
<table id="demo" lay-filter="test">
</table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">审批信息</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">一键删除</a>
</script>
<script type="text/javascript" src="${pageContext.request.contextPath}/webjars/layui/2.5.6/layui.js"></script>
<script>
    layui.use(['form', 'jquery', 'table','laydate', 'layer'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        var table = layui.table;
        var layer = layui.layer;
        var laydate = layui.laydate;
        //日期控件
        laydate.render({
            elem: '#test1' //指定元素
            ,format: 'yyyy-MM-dd'
        });
        //渲染表格组件
        var tableIns = table.render({
            elem: '#demo'//绑定表格元素，推荐使用ID选择器
            , height: 468
            , url: '/superAdminFind' //异步请求的地址,加入分页后，默认使用page(当前页码)和limit(每页显示数量)作为参数名称
            , page: true //开启分页
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter', 'exports', 'print']
            , cols: [[ //表头
                //field属性：字段属性，该属性与实体类的属性名一致
                //title属性：表头文本
                //sort标识是否排序
                {field: 'username', title: '用户名',width:90, fixed: 'left',align:"center"}
                ,{field: 'name', title: '姓名',width:100,align:"center"}
                ,{field: 'gender', title: '性别',width:90, align:"center"}
                ,{field: 'age', title: '年龄',width:90, align:"center"}
                ,{field: 'identity_card', title: '身份证',align:"center" }
                ,{field: 'phone', title: '电话',align:"center"}
                ,{field: 'proof', title: '核酸证明',width:90, align:"center"}
                ,{field: 'destination', title: '目的地',align:"center"}
                ,{field: 'adopt', title: '通过',width:90, align:"center"}
                ,{field: 'addtime', title: '添加时间',align:"center"}
                ,{field: 'remark', title: '备注',align:"center"}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', align: "center"}
            ]]
            , request: {
                pageName: 'pageNum' // 页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
        });
        //监听表格行工具栏
        table.on('tool(test)', function (obj) {

            switch (obj.event) {
                //编辑
                case 'edit':
                    openUpdateWindow(obj.data);
                    break;
                //删除
                case 'del':
                    deleteById(obj.data);
            }
        });
        var mainIndex;//窗口索引
        var url;//提交地址
        //更新用户信息
        function openUpdateWindow(data) {
            console.log(data)
            mainIndex = layer.open({
                type: 1,//弹出层类型
                title: "核对信息",
                area: ['600px', '600px'],
                content: $("#form_body"),//引用的窗口代码

                success: function () {
                    //表单数据回显
                    form.val("dataFrm", data);
                    //修改请求
                    url = "/superAdminUpdateInformation";
                }
            });
        }

        //删除用户
        function deleteById(data) {
            console.log(data);
            //提示用户确认是否删除
            layer.confirm("确定要删除么", {icon: 3, title: "提示"}, function (index) {
                //发送ajax请求
                $.post("/deleteAllInfo", {"identity_card": data.identity_card}, function (result) {
                    if (result.success) {
                        layer.alert(result.message, {icon: 1});
                        //刷新数据表格
                        tableIns.reload();
                    } else {
                        layer.alert(result.message, {icon: 2});
                    }
                }, "json");
                //关闭提示框
                layer.close(index);
            });
        }

        //监听表单提交事件
        form.on("submit(doSubmit)", function (data) {
            $.post(url, data.field, function (result) {
                if (result.success) {
                    layer.alert(result.message, {icon: 1});
                    //关闭窗口
                    layer.close(mainIndex);
                    //刷新数据表格
                    tableIns.reload();
                } else {
                    layer.alert(result.message, {icon: 2});
                }
            }, "json");
            return false;
        });

        //监听搜索按钮得提交开始
        form.on("submit(doSearch)", function (data) {
            tableIns.reload({
                url: '/moSelectByIdentityCard',
                where: data.field,//查询条件
                page: {
                    curr: 1
                }
            })
            //禁止页面刷新
            return false;
        })
        //监听搜索按钮结束
    });
</script>
</body>
</html>
